package com.cls.business.service.impl;

import com.cls.business.entity.DeclareTopic;
import com.cls.common.entity.QueryRequest;
import com.cls.business.entity.Indicator;
import com.cls.business.mapper.IndicatorMapper;
import com.cls.business.service.IIndicatorService;
import com.cls.system.entity.SysDict;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;
import com.github.pagehelper.PageHelper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Arrays;
import java.util.List;

/**
 * 评审指标表 Service实现
 *
 * @author slx
 * @date 2020-11-13 15:14:45
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class IndicatorServiceImpl extends ServiceImpl<IndicatorMapper, Indicator> implements IIndicatorService {

    @Override
    public PageInfo<Indicator> findIndicators(QueryRequest request, Indicator indicator) {
        LambdaQueryWrapper<Indicator> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        queryWrapper.eq(Indicator::getStandardId,indicator.getStandardId());
        List<Indicator> list= this.list(queryWrapper);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<Indicator> findIndicators(Indicator indicator) {
	    LambdaQueryWrapper<Indicator> queryWrapper = new LambdaQueryWrapper<>();
	    if(indicator.getStandardId()!=null){
	    queryWrapper.eq(Indicator::getStandardId, indicator.getStandardId());
        }
        queryWrapper.orderByDesc(Indicator::getCreateTime);
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createIndicator(Indicator indicator) {
        this.save(indicator);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateIndicator(Indicator indicator) {
        this.saveOrUpdate(indicator);
    }

    /**
    * 删除
    * @param ids
    */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteIndicators(String[] ids) {
        List< String > list = Arrays.asList(ids);
        this.removeByIds(list);
     }

}
